package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.hjq.shape.view.ShapeTextView;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.AetNumberFillInfoApi;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 可进行拷贝的副本
 */
public final class ComprehensiveAdapter extends AppAdapter<AetNumberFillInfoApi.Bean.QuestionSonListDTO> {
    private ComprehensiveAdapter2 adapter2;
    private OnChildListener mListener;
    public ComprehensiveAdapter(Context context,OnChildListener listener) {
        super(context);
        this.mListener = listener;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }


    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeTextView mTvTitle;
        private WrapRecyclerView mRvSelect;

        private ViewHolder() {

            super(R.layout.item_comprehensive1);
            mTvTitle = findViewById(R.id.tv_title);
            mRvSelect = findViewById(R.id.rv_select);
            mRvSelect.setLayoutManager(new LinearLayoutManager(getContext()));
            adapter2 = new ComprehensiveAdapter2(getContext(), new ComprehensiveAdapter2.OnChildListener() {
                @Override
                public void selectNumber(int fatherPersion,int persion) {
                    mListener.selectNumber(fatherPersion,persion);
                }
            });
            mRvSelect.setAdapter(adapter2);
            setIsRecyclable(false);
        }

        @Override
        public void onBindView(int position) {
            for (AetNumberFillInfoApi.Bean.QuestionSonListDTO.QuestionAnswerDTO bean2:getItem(position).getQuestion_answer()) {
                bean2.setFaposition(position);
            }

            adapter2.setData(getItem(position).getQuestion_answer());
//            adapter2.setItemSel(position);
            //试题类型 1单选 2判断 3多选 5 填空 6简答 7论述题 8 完型填空
            if (getItem(position).getType()==1){
                mTvTitle.setText("【单选题】"+getItem(position).getTitle());
            }else if (getItem(position).getType()==2){
                mTvTitle.setText("【判断题】"+getItem(position).getTitle());
            }else if (getItem(position).getType()==3){
                mTvTitle.setText("【多选题】"+getItem(position).getTitle());
            }else if (getItem(position).getType()==5){
                mTvTitle.setText("【填空题】"+getItem(position).getTitle());
            }else if (getItem(position).getType()==6){
                mTvTitle.setText("【简答题】"+getItem(position).getTitle());
            }else if (getItem(position).getType()==7){
                mTvTitle.setText("【论述题】"+getItem(position).getTitle());
            }else if (getItem(position).getType()==8){
                mTvTitle.setText("【完型填空题】"+getItem(position).getTitle());
            }

        }
    }
    public interface OnChildListener{
        //题号
        void selectNumber(int fatherPersion,int persion);
    }
}